<script setup lang='ts'>
  import { onMounted, reactive, ref } from 'vue';
  import { guild_roomApi } from '@/api/controller';
  import { Toastloading, ToastWarning, ToastSuccess } from '@/utils/public';
  import Pagination from "@/components/Pagination/index.vue";
  import xmImage from '@/components/xmImage/index.vue';
  import giveForm from './giveForm.vue';
  import { ElMessageBox } from 'element-plus';
  const giveFormRef = ref()
  const action = reactive({
    total:0,
    list:[] as any[],
  })
  const initialQuery = {
    page: 1,
    limit: 20,
    frame_id:'',
    frame_name: ''
  }
  const listQuery = reactive({
    ...initialQuery
  })
  const handleSerach = () => {
    listQuery.page = 1;
    getList();
  };
  const resetQuery = () => {
    Object.assign(listQuery, {
      ...initialQuery
    });
    getList()
  };
  const handlegiveForm = (row:any = {})=>{
    giveFormRef.value.openDialog(row)
  }
  const handleDel = (row:any={})=>{
    const { room_name='', id:log_id } = row
    ElMessageBox.confirm(`确定删除房间：${room_name}的下发记录吗？`, '提示',
    {
      confirmButtonText: '确定',
      cancelButtonText: '取消',
      type: 'warning',
    }).then(() => {
      const loading = Toastloading()
      guild_roomApi.roomFrameUserDel({
        log_id
      }).then(()=>{
        ToastSuccess('删除成功')
        getList()
        loading.close()
      }).catch(()=>{
        loading.close()
      })
    }).catch(() => { })
  }
  const getList = async()=> {
    const loading = Toastloading()
    const res = await guild_roomApi.roomFrameLogList(listQuery)
    loading.close()
    const { data=[], total=0, } = res?.data || {}
    action.total = total
    action.list = data
  }
  onMounted(()=>{
    getList()
  })
</script>

<template>
  <div class="xm-content">
    <div class="xm-headTab">
      <div class="labelBox">
        <div class="labelItem">
          <div class="label">装饰框ID：</div>
          <el-input :validate-event="false" v-model="listQuery.frame_id" placeholder="请输入装饰框ID"/>
        </div>
        <div class="labelItem">
          <div class="label">装饰框名称：</div>
          <el-input :validate-event="false" v-model="listQuery.frame_name" placeholder="请输入装饰框名称"/>
        </div>
      </div>
      <div class="labelBox"> 
        <div class="labelItem">
          <el-button type="primary" @click="handleSerach">查询</el-button>
          <el-button type="primary" @click="resetQuery">重置</el-button>
          <el-button type="primary" v-rule="'room_frameLogAdd'" @click="handlegiveForm({})">赠送</el-button>
        </div>
      </div>
    </div>
    <el-table
      class="xm-main xm-TableCenter"
      :data="action.list"
      border
    >
      <el-table-column width="100" prop="id" label="记录ID" />
      <el-table-column width="100" prop="room_uid" label="房间UUID" />
      <el-table-column width="100" prop="room_id" label="房间ID" />
      <el-table-column min-width="140" show-overflow-tooltip prop="room_name" label="房间昵称" />
      <el-table-column min-width="140" show-overflow-tooltip prop="union_name" label="房间公会" />
      <el-table-column width="100" prop="frame_id" label="装饰框ID" />
      <el-table-column min-width="140" show-overflow-tooltip prop="frame_name" label="装饰框名称" />
      <el-table-column width="160" prop="frame_img" label="装饰框图片">
        <template #default="scoped">
          <xmImage :src="scoped.row.frame_img" :list="[scoped.row.frame_img]" />
        </template>
      </el-table-column>
      <el-table-column width="180" prop="time_st" label="开始时间" />
      <el-table-column width="180" prop="time_et" label="结束时间" />
      <el-table-column width="180" prop="admin_name" label="操作人" />
      <el-table-column width="180" prop="updated_at" label="操作时间" />
      <el-table-column fixed="right" width="180"  label="操作" >
        <template #default="scoped">
          <el-button type="primary" v-rule="'room_frameLogEdit'" @click="handlegiveForm(scoped.row)">编辑</el-button>
          <el-button type="danger" v-rule="'room_frameLogDel'" @click="handleDel(scoped.row)">删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    <Pagination v-show="action.total > 0" :total="action.total" v-model:page="listQuery.page"
      v-model:limit="listQuery.limit" @pagination="getList" />
    <giveForm ref="giveFormRef" @update-list="getList" />
  </div>
</template>